package com.yzt.message.fragment;

import android.app.Dialog;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;

import com.yzt.zhuju.dialog.NewBaseBottomDialog;
import com.yzt.message.R;

/**
 * 消息列表设置弹窗
 */
public class MessageListSettingDialog extends NewBaseBottomDialog implements View.OnClickListener {

    public static final int TYPE_SET_HAVE_READ = 1;
    public static final int TYPE_DELETE_STRANGER_MESSAGE = 2;
    public static final int TYPE_DELETE_ALL_MESSAGE = 3;
    /**
     * 一键清理所有私信
     */
    public static final int TYPE_DELETE_ALL_PRIVATE = 4;
    private OnItemClickListener listener;

    public void setListener(OnItemClickListener listener) {
        this.listener = listener;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.dialog_message_list_setting, container, false);
        initView(view);
        return view;
    }

    private void initView(View view) {
        view.findViewById(R.id.tv_action_set_have_read).setOnClickListener(this);
        view.findViewById(R.id.tv_action_delete_stranger_message).setOnClickListener(this);
        view.findViewById(R.id.tv_action_delete_all_message).setOnClickListener(this);
        view.findViewById(R.id.tv_action_cancel).setOnClickListener(this);
    }

    @Override
    public void onStart() {
        super.onStart();
        Dialog dialog = getDialog();
        Window window = dialog.getWindow();
        if (window != null) {
            window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
            WindowManager.LayoutParams params = window.getAttributes();
            params.gravity = Gravity.BOTTOM;
            params.width = ViewGroup.LayoutParams.MATCH_PARENT;
            params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
            window.setAttributes(params);
        }
        dialog.setCanceledOnTouchOutside(true);
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.tv_action_set_have_read) {
            if (listener != null) {
                listener.onItemClick(TYPE_SET_HAVE_READ);
            }
        } else if (v.getId() == R.id.tv_action_delete_stranger_message) {
            if (listener != null) {
                listener.onItemClick(TYPE_DELETE_STRANGER_MESSAGE);
            }
        } else if (v.getId() == R.id.tv_action_delete_all_message) {
            if (listener != null) {
                listener.onItemClick(TYPE_DELETE_ALL_MESSAGE);
            }
        } else if (v.getId() == R.id.tv_action_cancel) {
            dismiss();
        }
    }

    public interface OnItemClickListener {

        void onItemClick(int type);
    }
}
